﻿using BLL;
using Model;
using PSIMIS2019.Comm;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace PSIMIS2019.SubPages
{
    public partial class _ExaminPurchaseBill : PSIMIS2019.Templates.BasePurchaseBillForm
    {
        public string CurrentUserID { get; set; }//当前登录用户ID
        List<string> pendingIDList;//待审核订单列表泛型集合
        ExaminPurchaseBillBLL bl;//审核页面业务逻辑类
        string opera;//记录操作类型。审核通过：YES；审核不通过：NO（由学生定义的）

        public _ExaminPurchaseBill()
        {
            InitializeComponent();
            bl = new ExaminPurchaseBillBLL();
            lbPurchaseBill.Enabled = true;
        }
        /// <summary>
        /// 获取待审核订单列表
        /// </summary>
        private List<string> GetPendingPurchaseBill()
        {
            pendingIDList=bl.GetPendingPurchaseBill();
            return pendingIDList;
        }

        private void lbPurchaseBill_VisibleChanged(object sender, EventArgs e)
        {
            if (GetPendingPurchaseBill().Count == 0)
            {
                lbPurchaseBill.DataSource = null;
            }
            else
            {
                lbPurchaseBill.DataSource = GetPendingPurchaseBill();
                lbPurchaseBill.SelectedIndex = -1;
            }
        }
        /// <summary>
        /// 获取控件值
        /// </summary>
        private void GetValues()
        {
            bo = new PurchaseBill();
            bo.PurchaseBillID = txtPurchaseID.Text.Trim();
            bo.Examiner = "800001";
            bo.Memo = txtMemo.Text;
        }

        private void btnPass_Click(object sender, EventArgs e)
        {
            btnNoPass.Enabled = false;
            GetValues();
            opera = "YES";
        }

        private void btnNoPass_Click(object sender, EventArgs e)
        {
            btnPass.Enabled = false;
            GetValues();
            opera = "NO";
        }

        private void btnConfirm_Click(object sender, EventArgs e)
        {
            if (opera == "YES")
                if(bl.PassExamine(bo))
                {
                    MessageBox.Show("订单审核通过！", "系统提示：");
                    lbPurchaseBill.DataSource = GetPendingPurchaseBill();//更新ListBox控件数据源
                }
            if (opera == "NO")
                if (bl.NoPassExamine(bo))
                {
                    MessageBox.Show("订单审核不通过！", "系统提示：");
                    lbPurchaseBill.DataSource = GetPendingPurchaseBill();//更新ListBox控件数据源
                }
            btnPass.Enabled = btnNoPass.Enabled = true;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            btnPass.Enabled = btnNoPass.Enabled = true;
            ClearControls.ClearControl(this);
            lbPurchaseBill.DataSource = GetPendingPurchaseBill();//更新ListBox控件数据源
        }
    }
}
